import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/22 9:38
 * @description 哈希表 + TreeMap
 */
public class TimeMap {
    Map<String, TreeMap<Integer, String>> map;
    public TimeMap() {
        map = new HashMap<>();
    }

    public void set(String key, String value, int timestamp) {
        TreeMap<Integer, String> treeMap;
        treeMap = map.getOrDefault(key, new TreeMap<>());
        treeMap.put(timestamp, value);
        map.put(key, treeMap);
    }

    public String get(String key, int timestamp) {
        if (!map.containsKey(key)) {
            return "";
        }
        Object maxIndex = map.get(key).floorKey(timestamp);
        if (maxIndex == null) {
            return "";
        }
        return map.get(key).get((int) maxIndex);
    }
}
